package com.ruoyi.web.controller.app;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.app.domain.AppReport;
import com.ruoyi.app.domain.bo.AppImComplaintBo;
import com.ruoyi.app.domain.vo.AppImComplaintVo;
import com.ruoyi.app.domain.vo.AppReportVo;
import com.ruoyi.app.service.IAppImComplaintService;
import com.ruoyi.app.service.IAppReportService;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 投诉
 *
 * @author ruoyi
 * @date 2025-11-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/imComplaint")
public class AppImComplaintController extends BaseController {

    private final IAppImComplaintService iAppImComplaintService;

    private final IAppReportService iAppReportService;

    /**
     * 查询投诉类型列表
     */
    @GetMapping("/complaintTypeList")
    public R<List<AppReport>> complaintTypeList(@Param("type") Integer type) {
        List<AppReport> AppImComplaintVo = iAppReportService.complaintTypeList(type);
        return R.ok(AppImComplaintVo);
    }

    /**
     * 查询投诉列表
     */
    @GetMapping("/list")
    public TableDataInfo<AppImComplaintVo> list(AppImComplaintBo bo, PageQuery pageQuery) {
        TableDataInfo<AppImComplaintVo> appImComplaintVoTableDataInfo = iAppImComplaintService.queryPageList(bo, pageQuery);
        return appImComplaintVoTableDataInfo;
    }

    /**
     * 导出投诉列表
     */
    @Log(title = "投诉", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AppImComplaintBo bo, HttpServletResponse response) {
        List<AppImComplaintVo> list = iAppImComplaintService.queryList(bo);
        ExcelUtil.exportExcel(list, "投诉", AppImComplaintVo.class, response);
    }

    /**
     * 获取投诉详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<AppImComplaintVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iAppImComplaintService.queryById(id));
    }

    /**
     * 新增投诉
     */
    @Log(title = "投诉", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody AppImComplaintBo bo) {
        bo.setUserId(getLoginUser().getUserId().toString());
        return toAjax(iAppImComplaintService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改投诉
     */
    @Log(title = "投诉", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AppImComplaintBo bo) {
        return toAjax(iAppImComplaintService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除投诉
     *
     * @param ids 主键串
     */
    @Log(title = "投诉", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iAppImComplaintService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
